import { defineConfig } from "vite";
import vue from '@vitejs/plugin-vue'
// @路径插件
import path from 'path'
// 自动引入API
import AutoImport from 'unplugin-auto-import/vite'
// 自动引入组件
import Components from 'unplugin-vue-components/vite'
// Svg插件
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons'
// ElementPlus
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
// 本地启用
import legacy from '@vitejs/plugin-legacy'
export default defineConfig({
	base:"./",
	server: {
		// 端口
		port: 1323,
	},
	plugins: [
		vue(),
		legacy({
			targets:["defaults","not IE 11"],
		}),
		AutoImport({
			// 自动引入API
			include: [
                /\.[tj]sx?$/, // .ts, .tsx, .js, .jsx
                /\.vue$/,
                /\.vue\?vue/, // .vue
            ],
			imports: ['vue', 'vue-router', 'pinia'],
			resolvers: [ElementPlusResolver()],
			dts: 'auto-imports.d.ts',
		}),
		Components({
			dirs: ['src/components'],
			dts: 'components.d.ts',
			resolvers: [ElementPlusResolver()],
		}),
		createSvgIconsPlugin({
			// 需要自动导入的 svg 文件目录 (可自行修改)我的路径如下图所示
			iconDirs: [path.resolve(process.cwd(), 'src/assets/svg')],
			// 执行icon name的格式 (可自行修改)
			symbolId: 'icon-[dir]-[name]',
		}),
	],
	css: {
		preprocessorOptions: {
			scss: {
				// 引入 index.scss 这样就可以在全局中使用 index.scss中预定义的变量了
				additionalData: '@import "@/style/index.scss";'
			}
		},
		postcss: {
			plugins: [

			],
		},
	},
	resolve: {
		alias: {
		  '@': path.resolve(__dirname, './src')
		}
	}
})